﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JHSoft.Extension
{
    public static class DistinctExtensions
    {
        public static IEnumerable<T> Distinct<T, V>(this IEnumerable<T> source, Func<T, V> keySelector)
        {
            return source.Distinct(new CommonEqualityComparer<T, V>(keySelector));
        }

        public static IEnumerable<T> Distinct<T, V>(this IEnumerable<T> source, Func<T, V> keySelector, IEqualityComparer<V> comparer)
        {
            return source.Distinct(new CommonEqualityComparer<T, V>(keySelector, comparer));
        }
    }

    public class Test
    {
        static Person[] data3 = new Person[] {
    new Person{ Id = 1, Name = "LDP"},
    new Person{ Id = 2, Name = "ldp"}
};
        Person[] ps3 = data3.Distinct(p => p.Name, StringComparer.CurrentCultureIgnoreCase)
            .ToArray();
    }

    internal class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}
